﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CtrLayer;
using ModelLayer;

namespace WCFLayer
{
        public class FlightRouteService : IFlightRouteService
    {
        private AirlineCtr airlineCtr;
        private BookingCtr bookingCtr;
        private PersonCtr personCtr;
        private PlaneCtr planeCtr;
        private Dijkstra dijkstra;
        public FlightRouteService()
        {
            airlineCtr = new AirlineCtr();
            bookingCtr = new BookingCtr();
            dijkstra = new Dijkstra();
            personCtr = new PersonCtr();
            planeCtr = new PlaneCtr();
        }
        #region Airline 
        public int InsertAirport(Airport _airport)
        {
            return airlineCtr.InsertAirport(_airport);
        }
        //Find and return airport by airportCode (string)
        public Airport FindAirportByCode(string _airportCode)
        {
            return airlineCtr.FindAirportByCode(_airportCode);
        }
        //Find and return airport by airportName (string)
        public Airport FindAirportByName(string _airportName)
        {
            return airlineCtr.FindAirportByName(_airportName);
        }
        //Update Airport by obj
        public int UpdateAirport(Airport _airport)
        {
            return airlineCtr.UpdateAirport(_airport);
        }
        //select all airports
        public List<Airport> SelectAllAirports()
        {
            return airlineCtr.SelectAllAirports();
        }
        //remove airport by obj
        public int RemoveAirport(Airport _airport)
        {
            return airlineCtr.RemoveAirport(_airport);
        }

        #endregion
        #region Dijkstra
        public List<FlightInstance> GetCheapestRoute(Airport _startAirport, Airport _endAirport, DateTime _flyDate)
        {
            return dijkstra.GetCheapestRoute(_startAirport, _endAirport, _flyDate);
        }
        public List<FlightInstance> GetQuickestRoute(Airport _startAirport, Airport _endAirport, DateTime _flyDate)
        {
            return dijkstra.GetQuickestRoute(_startAirport, _endAirport, _flyDate);
        }
        #endregion
        #region Flight
        public int InsertFlight(Flight _flight)
        {
            return airlineCtr.InsertFlight(_flight);
        }
        //find flight by airport
        public List<Flight> FindFlightByAirport(string _airportCode)
        {
            return airlineCtr.FindFlightByAirport(_airportCode);
        }
        //Find and return Flight by routeId (string)
        public Flight FindFlightByID(int _routeId)
        {
            return airlineCtr.FindFlightByID(_routeId);
        }
        //Update Flight by obj
        public int UpdateFlight(Flight _flight)
        {
            return airlineCtr.UpdateFlight(_flight);
        }
        public List<Flight> SelectAllFlights()
        {
            return airlineCtr.SelectAllFlights();
        }
        //RemoveFlight in database
        public int RemoveFlight(Flight _flight)
        {
            return airlineCtr.RemoveFlight(_flight);
        }
        #endregion
        #region FlightInstance
        public int InsertFlightInstance(FlightInstance _flightInstance)
        {
            return bookingCtr.InsertFlightInstance(_flightInstance);
        }
        public List<FlightInstance> FindFlightInstaceByFlight(Flight _flight)
        {
            return bookingCtr.FindFlightInstanceByFlight(_flight);
        }
        public FlightInstance FindFlightInstanceById(int _id)
        {
            return bookingCtr.FindFlightInstanceById(_id);
        }
        public List<FlightInstance> FindFlightInstancesByFlightAndDate(Flight _flight, DateTime _date)
        {
            return bookingCtr.FindFlightInstancesByFlightAndDate(_flight, _date);
        }
        public List<FlightInstance> SelectAllFlightinstances()
        {
            return bookingCtr.SelectAllFlightInstances();
        }
        public int RemoveFlightInstance(FlightInstance _flightInstance)
        {
            return bookingCtr.RemoveFlightInstance(_flightInstance);
        }
        public int UpdateFlightInstace(FlightInstance _flightInstance)
        {
            return bookingCtr.UpdateFlightInstance(_flightInstance);
        }
        #endregion
        #region SeatBooking
        public int InsertSeatBooking(SeatBooking _seatBooking, int _travelId)
        {
            return bookingCtr.InsertSeatBooking(_seatBooking, _travelId);
        }
        public int RemoveSeatBooking(SeatBooking _seatBooking)
        {
            return bookingCtr.RemoveSeatBooking(_seatBooking);
        }
        public SeatBooking FindSeatBookingByFlightAndSeat(FlightInstance _flightinstance, Seat _seat)
        {
            return bookingCtr.FindSeatBookingByFlightAndSeat(_flightinstance, _seat);
        }
        public int UpdateSeatBooking(SeatBooking _seatBooking)
        {
            return bookingCtr.UpdateSeatBooking(_seatBooking);
        }
        public List<SeatBooking> SelectAllSeatBookings()
        {
            return bookingCtr.SelectAllSeatBookings();
        }
  
        #endregion
        #region Travel
        public int InsertTravel(Travel _travel)
        {
            return bookingCtr.InsertTravel(_travel);
        }
        public Travel FindTravel(int _travelId)
        {
            return bookingCtr.FindTravel(_travelId);
        }
        public int UpdateTravel(Travel _travel)
        {
            return bookingCtr.UpdateTravel(_travel);
        }
        public List<Travel> SelectAllTravels()
        {
            return bookingCtr.SelectAllTravels();
        }
        public int RemoveTravel(Travel _travel)
        {
            return bookingCtr.RemoveTravel(_travel);
        }

        #endregion
        #region Customer
        //Insert Customer in the database
        public int InsertCustomer(Customer _customer)
        {
            return personCtr.InsertCustomer(_customer);
        }
        //Find Person in the database
        public Customer FindCustomerByPhoneNumber(int _phoneNo)
        {
            return personCtr.FindCustomerByPhoneNumber(_phoneNo);
        }
        //Find Customer by string (First name)
        public List<Customer> SelectAll()
        {
            return personCtr.SelectAll();
        }
        //Updates customer in the database
        public int UpdateCustomer(Customer _customer)
        {
            return personCtr.UpdateCustomer(_customer);
        }
        //remove Customer in the database
        public int RemoveCustomer(Customer _customer)
        {
            return personCtr.RemoveCustomer(_customer);
        }
        #endregion
        #region Plane
        //Creates a Plane object and calls DB to insert it into database.
        public int InsertPlane(Plane _plane)
        {
            return planeCtr.InsertPlane(_plane);
        }
        //Calls DB to search database after a Plane object by planeNo
        public Plane FindPlaneByPlaneNo(string _planeNo)
        {
            return planeCtr.FindPlaneByPlaneNo(_planeNo);
        }
        public List<Plane> SelectAllPlanes()
        {
            return planeCtr.SelectAllPlanes();
        }
        //update Plane by obj
        public int UpdatePlane(Plane _plane)
        {
            return planeCtr.UpdatePlane(_plane);
        }
        //remove Plane by obj
        public int RemovePlane(Plane _plane)
        {
            return planeCtr.RemovePlane(_plane);
        }
        #endregion
        #region Seat
        //Creates a Seat object and calls DB to insert it into database.
        public int InsertSeat(Seat _seat)
        {
            return planeCtr.InsertSeat(_seat);
        }
        //remove Seat by obj
        public int RemoveSeat(Seat _seat)
        {
            return planeCtr.RemoveSeat(_seat);
        }
        //Calls DB to search database after a Seat object by seatNo
        public Seat FindSeatBySeatNoAndPlaneNo(string _seatNo, string _planeNo)
        {
            return planeCtr.FindSeatBySeatNoAndPlaneNo(_seatNo, _planeNo);
        }
        public List<Seat> SelectAllSeats()
        {
            return planeCtr.SelectAllSeats();
        }
        public List<Seat> SelectFreeSeats(FlightInstance _flightInstance)
        {
            return bookingCtr.FindFreeSeats(_flightInstance);
        }
        #endregion
    }
}
